package com.sx.pipeline.ui.wallet

import android.app.Application
import android.text.TextUtils
import com.blankj.utilcode.util.ToastUtils
import com.sx.mvvmlibs.base.BaseViewModel
import com.sx.mvvmlibs.event.SingleLiveEvent
import com.sx.mvvmlibs.http.CommonObserver
import com.sx.mvvmlibs.utils.Logs
import com.sx.mvvmlibs.utils.RxThreadHelper
import com.sx.pipeline.R
import com.sx.pipeline.app.config.OperatorNeedsType
import com.sx.pipeline.app.model.CYBaseViewModel
import com.sx.pipeline.repos.http.req.AddInquiryDTO
import com.sx.pipeline.repos.http.req.AuditTaskDTO
import com.sx.pipeline.repos.http.res.*

/**
 *    author : zhouyouqiang
 *    e-mail : 1638473898@qq.com
 *    date   : 2022/5/20 13:51
 *    desc   :
 *    version: 1.0
 */
class WalletVM(app: Application) : CYBaseViewModel(app) {

    /**
     * 获取钱包余额类型标题
     */
    fun getWalletTabsList(): List<String> {
        val tabs = mutableListOf<String>()
        tabs.add(getApplication<Application>().getString(R.string.txt_all))
        tabs.add(getApplication<Application>().getString(R.string.txt_income))
        tabs.add(getApplication<Application>().getString(R.string.txt_outcome))
        return tabs
    }

    /**
     * 获取钱包余额类型标题id
     */
    fun getWalletTabsId(): List<String> {
        val tabs = mutableListOf<String>()
        tabs.add("")
        tabs.add("1")
        tabs.add("0")
        return tabs
    }



    /**
     * 钱包记录列表
     */
    val walletListEvent: SingleLiveEvent<Ipage<BalanceRecordVO>> = SingleLiveEvent()
    fun getWalletBillList(income:String,page: Int = 1) {
        addSubscribe(
            mModel.getWalletBillList(income,page)
                .compose(RxThreadHelper.rxSchedulerHelper())
                .subscribeWith(object : CommonObserver<Ipage<BalanceRecordVO>, BaseViewModel<*>>
                    (this, false) {
                    override fun onResult(result: Ipage<BalanceRecordVO>) {
                        walletListEvent.postValue(result)
                        mUI.initRefreshEvent().postValue(true)
                        if (page != 1) {
                            mUI.initLoadEvent().postValue(true)
                        }
                    }

                    override fun onFailed(code: Int, msg: String?) {
                        super.onFailed(code, msg)
                        ToastUtils.showShort(msg)
                        mUI.initRefreshEvent().postValue(false)
                        if (page != 1) {
                            mUI.initLoadEvent().postValue(true)
                        }
                    }
                })
        )
    }

}